import 'package:flutter/material.dart';
import 'package:my_audio_recorder/my_audio_recorder.dart';
import 'package:my_audio_recorder_example/Ext/StringExt.dart';

import '../Bean/AudioRecordItem.dart';
import '../Ext/ColorUtil.dart';

class ListItem extends StatefulWidget {
  const ListItem({super.key, required this.recordItem});

  final AudioRecordItem recordItem;

  @override
  State<ListItem> createState() => _ListItem();
}


class _ListItem extends State<ListItem> {

  final _myAudioRecorderPlugin = MyAudioRecorder();


  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () async {
        '播放录音${widget.recordItem.name}'.toastSuccess(context);
        _myAudioRecorderPlugin.playAudio(widget.recordItem.filePath!);
      },
      child: Container(
        margin: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0),
        padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 15.0),
        decoration: const BoxDecoration(
          color: Color(0xFFFFFFFF),
          borderRadius: BorderRadius.all(Radius.circular(10.0)),
        ),
        child: Container(
          padding: const EdgeInsets.symmetric(vertical: 10),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Container(
                  margin:
                      const EdgeInsets.symmetric(vertical: 5.0, horizontal: 5.0),
                  child: const Icon(Icons.play_circle_filled_sharp, size: 35)),
              Container(
                margin: const EdgeInsets.symmetric(horizontal: 10.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '${widget.recordItem.name}',
                      style: const TextStyle(fontSize: 18),
                    ),
                    const SizedBox(height: 2),
                    Text('${widget.recordItem.time}',
                        style: TextStyle(color: ColorUtil.stringColor("#a7a9a6")))
                  ],
                ),
              ),
              const Spacer()
            ],
          ),
        ),
      ),
    );
  }
}
